<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/public/header.jsp"%>

<html>
	<head>
		<title>项目收票管理</title>
	</head>
	<script type="text/javascript">
		$(function(){
			$("#searchValue").keypress(function(e) { 
		    	// 回车键事件 
		     	if(e.which == 13) { 
		     		 doSearch();
		       	} 
		   	});
			$("#dept_id").combotree({
				url:'<%=contextPath %>/springMVC/group/listDepartment',
				method:'POST',
				animate:true,
				lines:true,
				onChange:function(){
					doSearch();
				}
			});
			$("#table").datagrid({
				title:"项目收票管理",
				iconCls:'icon-edit',
				loadMsg:'正在加载数据，请稍后......',
				url:'<%=contextPath %>/springMVC/xmFinance/listPageXMRecInvoice',
				rownumbers:true,
				fitColumns:true,
				idField:'id',
				nowrap:false,
				frozenColumns:[[
				    {title:'主键',field:'id',hidden:true},
				    {title:'凭证id',field:'invoice_id',hidden:true},
				    {title:'项目id',field:'xm_id',hidden:true}
				]],
				columns:[[
					{title:'票号',field:'ticket',width:150,align:'center',sortable:true},
					{title:'日期',field:'operation_time',width:150,align:'center',sortable:true},
					{title:'部门',field:'dept_name',width:100,align:'center'},
					{title:'项目编号',field:'xm_code',width:100,align:'center'},
					{title:'项目名称',field:'xm_name',width:100,align:'center'},
					{title:'收票对象',field:'rec_to_name',width:100,align:'center'},
					{title:'收票金额',field:'rec_value',width:100,align:'center'},
					{title:'经办人',field:'creator',width:100,align:'center'},
					{title:'收票来由',field:'source',width:30,hidden:true,align:'center'},
					{title:'确认状态',field:'flag',width:30,hidden:true,align:'center'},
					{title:'收票类型',field:'rec_type',hidden:true,align:'center',formatter:function(value,rowData,rowIndex){
						if(value==1){
							return "分包商";
						}else if(value==2){
							return "采购商";
						}
					}},
					{title:'摘要',field:'remark',width:200,align:'center'},
					{title:'详情操作',field:'more',width:150,align:'center',formatter:function(value,rowData,rowIndex){
							var str="";
							if(rowData.source==1||rowData.flag==1){
								if(rowData.source==1){
								str+= "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-modify' title='添加分包票据号码' onclick=\"javascript:addOrEditRecInvoice(3,'"+rowData.id+"','"+rowData.xm_id+"','"+rowData.rec_type+"','"+rowData.source+"','"+rowData.invoice_id+"','"+rowData.ticket+"');\"/> &nbsp;&nbsp;";
								}
								str+= "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-details' title='详情' onclick=\"javascript:addOrEditRecInvoice(2,'"+rowData.id+"','"+rowData.xm_id+"','"+rowData.rec_type+"','"+rowData.source+"','"+rowData.invoice_id+"','"+rowData.ticket+"');\"/>";
								
							}else{
							str+= "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-modify' title='编辑' onclick=\"javascript:addOrEditRecInvoice(1,'"+rowData.id+"','"+rowData.xm_id+"','"+rowData.rec_type+"','"+rowData.source+"','"+rowData.invoice_id+"','');\"/> &nbsp;&nbsp;";
							str+= "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-no' title='删除' onclick=\"javascript:deleteData('"+rowData.id+"');\"/>&nbsp;&nbsp;";
	                    	str+= "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-details' title='详情' onclick=\"javascript:addOrEditRecInvoice(2,'"+rowData.id+"','"+rowData.xm_id+"','"+rowData.rec_type+"','"+rowData.source+"','"+rowData.invoice_id+"','');\"/>&nbsp;&nbsp;";
	                    	str+= "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-ok' title='确认' onclick=\"javascript:updateXmRecFlag('"+rowData.id+"','"+rowData.rec_value+"','"+rowData.xm_id+"','"+rowData.rec_type+"');\"/>";
							}
	                    return str;
					}}
				]],
				toolbar:"#tb",
				pageSize:10,
				pageList : [10,50,100],  
				pagination:true,
				onLoadSuccess:function(rtJson){
					if(rtJson.rtState== '1')
					{
						$.messager.alert('提示',rtJson.rtMsrg);
					}
				}
			});
		});
		function addOrEditRecInvoice(type,id,xm_id,rec_type,source,invoice_id,ticket){
			if(ticket == 'undefined'){
				ticket = "";
			}
			if(source==1){
				if(type==3){
					openDialogResize("<%=contextPath %>/springViews/xm/addOrEditInvoice.jsp?id="+invoice_id+"&rec_id="+id+"&ticket="+ticket+"&xm_id="+xm_id+"&callback=rtCallBack&isShow=3",1000, 800);
				}else{
					openDialogResize("<%=contextPath %>/springViews/xm/addOrEditInvoice.jsp?id="+invoice_id+"&ticket="+ticket+"&callback=rtCallBack&isShow=1",1000, 800);
				}
			}else{
				
        	if(type==0){
        			openDialogResize("<%=contextPath %>/springViews/xm/recInvoiceManage.jsp?callback=rtCallBack",1000, 800);
        	}else if(type==1){
        		if(rec_type==1){
        			openDialogResize("<%=contextPath %>/springViews/xm/addOrEditRecInvoice.jsp?id="+id+"&xm_id="+xm_id+"&callback=rtCallBack",1000, 800);
        			
        		}else{
        			openDialogResize("<%=contextPath %>/springViews/xm/addOrEditSupRecInvoice.jsp?id="+id+"&xm_id="+xm_id+"&callback=rtCallBack",1000, 800);
        		}
        	
        	}else if (type ==3){
        		if(rec_type==1){
                	openDialogResize("<%=contextPath %>/springViews/xm/addOrEditRecInvoice.jsp?id="+id+"&xm_id="+xm_id+"&callback=rtCallBack&isShow=3",1000, 800);
        			
        		}else{
                	openDialogResize("<%=contextPath %>/springViews/xm/addOrEditSupRecInvoice.jsp?id="+id+"&xm_id="+xm_id+"&callback=rtCallBack&isShow=3",1000, 800);
        		}
        		
        	}else{
        		if(rec_type==1){
                	openDialogResize("<%=contextPath %>/springViews/xm/addOrEditRecInvoice.jsp?id="+id+"&xm_id="+xm_id+"&callback=rtCallBack&isShow=1",1000, 800);
        			
        		}else{
                	openDialogResize("<%=contextPath %>/springViews/xm/addOrEditSupRecInvoice.jsp?id="+id+"&xm_id="+xm_id+"&callback=rtCallBack&isShow=1",1000, 800);
        		}
        	}
			}
        }
		
		function deleteData(id){
			var rows=$('#table').datagrid('getSelections');
			$.messager.confirm('确认','您确认删除该记录信息？',function(msg){
				if(msg){
					$.ajax({
						type:'POST',
						url:"<%=contextPath %>/springMVC/xmFinance/deleteRecInvoice",
						data:"ids="+id,
						success:function(rtJson){
							if(rtJson.rtState == '0'){
								table_reload(rows.length);
							}
							else{
								warningInfo(rtJson.rtMsrg);
							}
						}
					});
				}
			});
		}
		function updateXmRecFlag(id,rec_value,xm_id,rec_type){
			var rows=$('#table').datagrid('getSelections');
			$.messager.confirm('确认','您确认该记录信息正确吗？',function(msg){
				if(msg){
					$.ajax({
						type:'POST',
						url:"<%=contextPath %>/springMVC/xmFinance/updateXmRecFlag",
						data:"id="+id+"&rec_value="+rec_value+"&xm_id="+xm_id+"&rec_type="+rec_type,
						success:function(rtJson){
							if(rtJson.rtState == '0'){
								table_reload(rows.length);
							}
							else{
								warningInfo(rtJson.rtMsrg);
							}
						}
					});
				}
			});
		}
		 function deleteRows(){
				var rows=$('#table').datagrid('getSelections');
				var deleteVar="";
				if(rows.length==0)
				{
					$.messager.alert('提示','选中要删除的记录');  
					return ;
				}
				for(var i=0;i<rows.length;i++)
				{
					if(i==(rows.length-1))
					{
						deleteVar+=rows[i].id;
					}else
					{
						deleteVar+=rows[i].id+",";
					}
				}
				$.messager.confirm('确认','您确认删除该记录信息？',function(msg){
					if(msg){
						$.ajax({
							type:'POST',
							url:"<%=contextPath %>/springMVC/xmFinance/deleteRecInvoice",
							data:"ids="+deleteVar,
							dataType:"json",
							success:function(rtJson){
								if(rtJson.rtState == '0'){
									table_reload(rows.length);
								}
								else{
									warningInfo(rtJson.rtMsrg);
								}
							}
						});
					}
				});
			}
		function rtCallBack(){
			$('#table').datagrid('reload');
		}

		function doSearch()
		{
			var start_time=$('#start_time').datebox('getValue');  
			var end_time=$('#end_time').datebox('getValue');  
			var searchValue = $('#searchValue').val();
			var dept_id = $("#dept_id").combotree('getValue');
			$('#table').datagrid('load',{
				searchValue:searchValue,
				start_time:start_time,
				dept_id : dept_id,
				end_time:end_time
				
			});
		}
	</script>
		<body style="height: 97%">
		<div id="table" data-options="fit:true" ></div>
		<div id="tb" style="padding:3px;height:auto">
			<div style="float:left;">
				<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="addOrEditRecInvoice(0);">新增</a>
			</div>
			<div align="right">
				所属部门：<input  id="dept_id" name="dept_id" class="easyui-combotree">&nbsp;&nbsp; 
				开始时间：<input id="start_time" name="start_time" class="easyui-datebox" />&nbsp;&nbsp;&nbsp;结束时间：<input id="end_time" name="end_time" class="easyui-datebox" />
				项目编号/名称/票号：<input id="searchValue" name="searchValue" style="width:170px" title="项目编号/名称/票号" placeholder="项目编号/名称 /票号"  />&nbsp;&nbsp; 
				<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearch();"></a>
			</div>
		</div>
	</body>
</html>